<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    /* 2.人机猜拳游戏
    1)电脑玩家随机出拳
    2)用户玩家在页面弹窗输入你要出拳的内容
    3)比较输赢,对应输出一句话
    4)询问是否继续
    5)如果继续自动进入下一轮开始比赛
    6)如果否结束程序 */
    do {
        var user = prompt('请输入：石头、剪刀、布');
        var comput = Math.floor(Math.random(0, 1) * 3);
        if (comput == 0) {
            comput = '石头';
        }
        else if (comput == 1) {
            comput = '剪刀';
        }
        else if (comput == 2) {
            comput = '布';
        }
        if (user == '石头' && comput == '布' || user == '剪刀' && comput == '石头' || user == '布' && comput == '剪刀') {
            alert('你出的' + user + '，电脑出的' + comput + '，电脑赢了！');
        }
        else if (comput == '石头' && user == '布' || comput == '剪刀' && user == '石头' || comput == '布' && user == '剪刀') {
            alert('你出的' + user + '，电脑出的' + comput + '，你赢了！');
        }
        else {
            alert('你出的' + user + '，电脑出的' + comput + '，平局');
        }
        var a = confirm('是否进行下一局？');
    } while (a);
</script>

</html>